<?php

/**
 * Created by : Sandi Rizky Kharisma (sandi.informatics08@gmail.com)
 * This Class Generated for CRUD purpose only
 */
class m_faktur extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    public function get($where = null, $limit = null, $offset = null) {
        if ($where != null)
            $this->db->where($where);
        if ($limit != null && $offset != null)
            $this->db->limit($limit, $offset);
        return $this->db->get("faktur");
    }

    function get_all($limit, $uri) {

        $result = $this->db->get('faktur', $limit, $uri);
        if ($result->num_rows() > 0) {
            return $result->result_array();
        } else {
            return array();
        }
    }

    function get_one($id) {
        $this->db->where('NOMER_FAKTUR', $id);
        return $this->db->get('faktur');
        
    }

    function insert() {
        $data = array(
            //'ID_TOKO' => $this->input->post('ID_TOKO', TRUE),
            'NOMER_FAKTUR' => $this->input->post('NOMER_FAKTUR', TRUE),
            'TGL_FAKTUR' => $this->input->post('TGL_FAKTUR', TRUE),
            'ID_SUPLIER' => $this->input->post('SUPLIER', TRUE),
        );
        
        $this->db->insert('faktur', $data);
        return $this->db->insert_id();
    }

    function update($id) {
        $data = array(
            'NOMER_FAKTUR' => $this->input->post('NOMER_FAKTUR', TRUE),
            //'ID_TOKO' => $this->input->post('ID_TOKO', TRUE),
            'ID_SUPLIER' => $this->input->post('SUPLIER', TRUE),
            'TGL_FAKTUR' => $this->input->post('TGL_FAKTUR', TRUE),
            //'DISKON' => $this->input->post('DISKON', TRUE),
            //'PPN' => $this->input->post('PPN', TRUE),
            'TOTAL' => $this->input->post('ALL_TOTAL', TRUE),
        );
        $this->db->where('ID_FAKTUR', $id);
        return $this->db->update('faktur', $data);
    }

    function delete($id) {
        $this->db->where('NOMER_FAKTUR', $id);
        $this->db->delete('faktur');
    }

    function assign_bukti($id_bukti,$id_faktur){
        $data = array(
            'ID_FAKTUR' => $id_faktur,
            'ID_BUKTI_TRANSAKSI' => $id_bukti,
        );
        $this->db->where('ID_FAKTUR', $id_faktur);
        return $this->db->update('faktur', $data);
    }

}
?>
